package com.study.pojo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import javax.annotation.Resource;

/**
 * People class
 *
 * @author chenyeqing
 * @date 2020/12/21
 */
public class People {


    /**
     * 先根据 Type, Type 相同再根据 Name
     *
     * Could not autowire. There is more than one bean of 'Dog' type.
     * Beans:
     *      dog2    (bean.xml)
     *      dog22    (bean.xml)
      */
    @Autowired
    //@Qualifier(value = "dog2")
    private Dog dog;
    //@Autowired(required = false)
    //@Qualifier(value = "cat2")
    //private Cat cat;

    @Autowired(required = false)
    private Cat cat;
    //
    //@Resource(name = "dog22")
    //private Dog dog;

    private String name;

    public void show() {
        cat.shout();
        dog.shout();
        System.out.println("我叫" + name);
    }

    public People(Cat cat, Dog dog, String name) {
        this.cat = cat;
        this.dog = dog;
        this.name = name;
    }

    @Override
    public String toString() {
        return "People{" +
                "cat=" + cat +
                ", dog=" + dog +
                ", name='" + name + '\'' +
                '}';
    }

    public People() {
    }

    public Cat getCat() {
        return cat;
    }

    public Dog getDog() {
        return dog;
    }

    public void setDog(Dog dog) {
        this.dog = dog;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
